package com.chrray.position.service.web.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chrray.position.domain.FdFeedback;
import com.chrray.position.domain.FdJobCategory;
import com.chrray.position.domain.FdJobSubcategory;
import com.chrray.position.mapper.position.FdFeedbackMapper;
import com.chrray.position.mapper.position.FdJobCategoryMapper;
import com.chrray.position.mapper.position.FdJobSubcategoryMapper;
import com.chrray.position.pojo.dto.web.FdFeedBackExe;
import com.chrray.position.pojo.dto.web.FdJobCategoryExe;
import com.chrray.position.service.web.WFdFeedbackService;
import com.chrray.position.service.web.WFdJobCategoryService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 意见反馈表 接口实现类
 *
 * @author wusiwee
 * @email wusiwee@163.com
 * @since 1.0.1 2024-08-07
 */
@Service
@AllArgsConstructor
public class WFdJobCategoryServiceImpl extends ServiceImpl<FdJobCategoryMapper, FdJobCategory> implements WFdJobCategoryService {

    @Resource
    private FdJobSubcategoryMapper fdJobSubcategoryMapper;
    @Override
    public IPage pageList(FdJobCategoryExe entity) {
        LambdaQueryWrapper<FdJobCategory> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(!ObjectUtils.isEmpty(entity.getName()), FdJobCategory::getName, entity.getName());
        queryWrapper.orderByDesc(FdJobCategory::getCreatedTime);
        IPage page = entity.getPage();
        IPage<FdJobCategory> pageList = this.page(page, queryWrapper);
        pageList.getRecords().stream().forEach(
                fdJobCategory -> {
                    LambdaQueryWrapper<FdJobSubcategory> lambdaQueryWrapper=new LambdaQueryWrapper<>();
                    lambdaQueryWrapper.eq(FdJobSubcategory::getCategoryId,fdJobCategory.getId());
                    Integer categoryNum = fdJobSubcategoryMapper.selectCount(lambdaQueryWrapper);
                    fdJobCategory.setCategoryNum(categoryNum);
                }
        );
        return  pageList;
    }
}
